import Pages from '../../../pages/pages.vue'
import { showMsg, prizeResultList, setMenuType } from '../../../../vuex/action'

export default {
  name: 'result-list',
  data() {
    return {
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      },
      prizeRList: [],
      searchType: 1,
      searchTxt: '',
      typePrize: 0,
      totalCount: 0
    }
  },
  vuex: {
    getters: {
      activityId: state => state.activityStoreId,
      activityName: state => state.activityStoreName
    },
    actions: {
      xPrizeResultList: prizeResultList,
      xShowMsg: showMsg,
      xSetMenuType: setMenuType
    }
  },
  components: {
    'vue-pages': Pages
  },
  ready() {
    this.xSetMenuType('activity')
    this.getList({})
  },
  methods: {
    getList({start=this.pages.start, limit=this.pages.limit, txt=this.searchTxt, activityId=this.activityId}) {
      let param = {
        start: start,
        limit: limit,
        activityId: +activityId
      }

      if (txt.length || (this.typePrize || this.typePrize === 0)) {
        switch (+this.searchType) {
          case 1:
            param.name = txt
            break
          case 2:
            param.type = +this.typePrize
            break
          case 3:
            param.phone = txt
            break
          default:
        }
      }

      this.xPrizeResultList(param)
        .then((data) => {
          this.prizeRList = data.list
          this.totalCount = data.totalcount
          this.pages.totalPages = Math.ceil(data.totalcount / limit)
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    courseManage() {
      this.$route.router.go('/result/course/' + this.activityId)
    }
  }
}
